/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Visualizer.java
 *
 * Created on 11.05.2010, 13:44:24
 */
package trinomialtree.treevisualizer;

import java.util.List;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import trinomialtree.gui.TrinomialTreeView;
import trinomialtree.gui.TrinomialTreeView.mode;
import trinomialtree.input.RateInputReader;
import trinomialtree.math.TrinomialTree;

/**
 *
 * @author pl
 */
public class Visualizer extends javax.swing.JFrame {

    /** Creates new form Visualizer */
    public Visualizer(final TrinomialTree tree) {
        //initComponents();

        setSize(1300, 680);
        this.setTitle("Trinomialtree Visualizer");
        JPanel panel = new VisualizerPanel(tree);
        JScrollPane pane = new JScrollPane(panel);
        pane.setViewportView(panel);
        getContentPane().add(pane);



    }

    /**
     * Generate a dummy tree for test purposes
     */
    private static TrinomialTree generateDummyTree() {

        RateInputReader reader = new RateInputReader(TrinomialTreeView.RATE_INPUT);
        List zinsListe = null;

        double deltat = 1d / 12;
        //double deltat = 1d/12;
        //double deltat = 1d/12;

        try {
            zinsListe = reader.getRates(0, 1);
        } catch (Exception e) {
            e.printStackTrace();
        }


        TrinomialTree tree = new TrinomialTree(zinsListe, deltat, mode.WEEK);

        tree.calculateEuropeanPut(2, 3, 0.97d, 1);

        return tree;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(trinomialtree.gui.TrinomialTreeApp.class).getContext().getResourceMap(Visualizer.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 1310, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 836, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Visualizer(generateDummyTree()).setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
}
